package com.freshcity.manager.support
{
	import com.freshcity.ILayer;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.utils.*;

	public class UIMaskEffect extends Sprite
	{
		private var _masks:Array;
		private var _layer:DisplayObjectContainer;
		private var _timeKey:uint;
		private var isShow:Boolean;
		
		public function UIMaskEffect(layer:Sprite)
		{
			this._layer = layer;
		}
		
		private function drawMask():void
		{
			var loc1:*=null;
			graphics.clear();
			graphics.lineStyle(0, 0, 0);
			if(isShow){
				graphics.beginFill(0, 0.4);
			}else{
				graphics.beginFill(0xffffff, 0);
			}
			graphics.drawRect(0, 0, _layer.stage.stageWidth,_layer.stage.stageHeight);
			if (this._masks) 
			{
				var loc2:*=0;
				var loc3:*=this._masks;
				label240: for each (loc1 in loc3) 
				{
					var loc4:*=loc1.shape;
					switch (loc4) 
					{
						case MaskInfo.Shape_Cycle:
						{
							graphics.drawCircle(loc1.x, loc1.y, loc1.width);
							continue label240;
						}
						case MaskInfo.Shape_Rect:
						{
							graphics.drawRect(loc1.x, loc1.y, loc1.width, loc1.height);
							continue label240;
						}
					}
				}
			}
			graphics.endFill();
		}
		
		private function onTimeOutHandler():void
		{
			this.hideMask();
			return;
		}
		
		public function showMask(arg1:Array, arg2:int=10000,isShow:Boolean=false):void
		{
			this.hideMask();
			this.isShow=isShow;
			this._masks = arg1;
			this.drawMask();
			this._layer.addChild(this);
			if (arg2 > 0) 
			{
				this._timeKey = setTimeout(this.onTimeOutHandler, arg2);
			}
		}
		
		public function hideMask():void
		{
			clearTimeout(this._timeKey);
			graphics.clear();
			if (this._masks) 
			{
				this._masks.length = 0;
			}
			if (this._layer.contains(this)) 
			{
				this._layer.removeChild(this);
			}
		}
		
		public function get isHide():Boolean
		{
			return this.parent == null;
		}
		
		public function stageResize():void
		{
			if (this.parent) 
			{
				this.drawMask();
			}
		}
	}
}